package ro.k.startUP;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

import ro.k.web.beans.UserBean;

public class UsearBeanHelpper {
	
	private final static String fileName = "c:\\userBean.xml"; 
	private final static String fileNameList = "c:\\userBeans.xml";
	
    public static void write(UserBean f) throws Exception{
        XMLEncoder encoder =
           new XMLEncoder(
              new BufferedOutputStream(
                new FileOutputStream(fileName)));
        encoder.writeObject(f);
        encoder.close();
    }
    
    public static void write(List<UserBean> f) throws Exception{
        XMLEncoder encoder =
           new XMLEncoder(
              new BufferedOutputStream(
                new FileOutputStream(fileNameList)));
        encoder.writeObject(f);
        encoder.close();
    }

    public static UserBean read() throws Exception {
        XMLDecoder decoder =
            new XMLDecoder(new BufferedInputStream(
                new FileInputStream(fileName)));
        UserBean o = (UserBean) decoder.readObject();
        decoder.close();
        return o;
    }
    
    public static List<UserBean> readList() throws Exception {
        XMLDecoder decoder =
            new XMLDecoder(new BufferedInputStream(
                new FileInputStream(fileName)));
        List<UserBean> o = (List<UserBean>) decoder.readObject();
        decoder.close();
        return o;
    }
    
    public static void main(String [] a){
    	try {
    		
    		List<UserBean> ubs = new ArrayList<UserBean>();
    		ubs.add(new UserBean("nme1","pss1"));
    		ubs.add(new UserBean("nme2","pss2"));
    		ubs.add(new UserBean("nme3","pss3"));
    		
			write(ubs);
			
		//	List<UserBean> ub = readList();
			
		//	System.out.println(ub.size());
			
		} catch (Exception e) {
			e.printStackTrace();
		}
    	
    	
    	
    	
    	
    	
    }
}